SELECT column1, column2, ... FROM 模式名.表名 [WHERE 條件] [GROUP BY 列名] [ORDER BY 列名 [ASC|DESC]] [HAVING 條件];
-- 創(chuàng)建學(xué)生表 CREATE TABLE STUDENTS( STUDENT_ID INTEGER PRIMARY KEY IDENTITY(1,1), NAME VARCHAR(50) NOT NULL, BIRTH_DATE DATE NOT NULL, GENDER CHAR(1) CHECK (GENDER IN ('M','F')) NOT NULL, EMAIL VARCHAR(100) UNIQUE NOT NULL, PHONE_NUMBER VARCHAR(15) ); -- 創(chuàng)建教師表 CREATE TABLE TEACHERS( TEACHER_ID INTEGER PRIMARY KEY IDENTITY(1,1), NAME VARCHAR(50) NOT NULL, EMAIL VARCHAR(100) UNIQUE NOT NULL, PHONE_NUMBER VARCHAR(15), TITLE VARCHAR(30) ); -- 創(chuàng)建課程表 CREATE TABLE COURSES( COURSE_ID INTEGER PRIMARY KEY IDENTITY(1,1), COURSE_NAME VARCHAR(100) NOT NULL, DESCRIPTION TEXT, CREDITS INTEGER NOT NULL ); -- 創(chuàng)建注冊表 CREATE TABLE REGISTRATIONS( STUDENT_ID INTEGER, COURSE_ID INTEGER, REGISTRATION_DATE DATE NOT NULL, GRADE CHAR(1) CHECK (GRADE IN ('A','B','C','D','F')), PRIMARY KEY (STUDENT_ID, COURSE_ID), FOREIGN KEY (STUDENT_ID) REFERENCES STUDENTS (STUDENT_ID), FOREIGN KEY (COURSE_ID) REFERENCES COURSES (COURSE_ID) ); -- 創(chuàng)建授課表 CREATE TABLE TEACHING_ASSIGNMENTS( TEACHER_ID INTEGER, COURSE_ID INTEGER, SEMESTER VARCHAR(10) NOT NULL, YEAR INTEGER NOT NULL, PRIMARY KEY (TEACHER_ID, COURSE_ID, SEMESTER, YEAR), FOREIGN KEY (TEACHER_ID) REFERENCES TEACHERS (TEACHER_ID), FOREIGN KEY (COURSE_ID) REFERENCES COURSES (COURSE_ID) ); -- 創(chuàng)建索引以優(yōu)化查詢性能(根據(jù)需要來創(chuàng)建) CREATE INDEX idx_students_email ON STUDENTS (EMAIL); CREATE INDEX idx_teachers_email ON TEACHERS (EMAIL); CREATE INDEX idx_courses_name ON COURSES (COURSE_NAME); CREATE INDEX idx_registrations_student ON REGISTRATIONS (STUDENT_ID); CREATE INDEX idx_registrations_course ON REGISTRATIONS (COURSE_ID); CREATE INDEX idx_teaching_assignments_teacher ON TEACHING_ASSIGNMENTS (TEACHER_ID); CREATE INDEX idx_teaching_assignments_course ON TEACHING_ASSIGNMENTS (COURSE_ID);
create or replace procedure mytest_proc( parm_OPType in int:=null, parm_cName in VARCHAR:='', parm_info OUT int:=null -- 輸出參數(shù):用戶信息 ) as declare inparm_sql VARCHAR2(100); -- 聲明局部變量 inparm_value VARCHAR2(100); -- 聲明局部變量 --declare --OPType int:=0; --cName varchar(50):=''; --counter int:=0; begin
if parm_OPType=101 begin --select 1 as iResult,'查詢到' as cResult; SELECT top 10 * from PRODUCTION."PRODUCT_CATEGORY" order by PRODUCT_CATEGORYID DESC;
--select count(*) into inparm_value from PRODUCTION."PRODUCT_CATEGORY"; --INTO -- parm_info := inparm_value; -- 將查詢結(jié)果賦值給輸出參數(shù) return; end ELSE BEGIN select -1 as iResult,'沒有查詢到' as cResult; return; --print('22222222'); end;